<template>
  <div id="myChart1" :style="{ width: '100%', height: '100%' }"></div>
</template>

<script>
import { defineComponent, toRefs, reactive, onMounted } from 'vue'
import * as echarts from 'echarts'

export default defineComponent({
  name: 'TransportBarChart',
  setup() {
    const state = reactive({
      option: {
        grid: {
          top: '25%',
          left: '2%',
          right: '15%',
          bottom: '20%',
          containLabel: true,
        },
        xAxis: [
          {
            type: 'category',
            name: '年份',
            data: ["2019","2020","2021","2022","2023","2024"],
            axisTick: {
              alignWithLabel: true,
            },
            nameTextStyle: {
              color: '#058CFF'
            },
            axisLabel: {
              textStyle: {
                color: '#AFC0D5'
              }
            },
          },
        ],
        yAxis: [
          {
            name: '单位（万）',
            type: 'value',
            nameTextStyle: {
              color: '#058CFF'
            },
            axisLine: {
              show: true
            },
            splitLine: {     //网格线
              show: false
            },
            axisLabel: {
              textStyle: {
                color: '#AFC0D5'
              }
            },
          },
        ],
        legend: {
          data: ['中小型', 'Q-Flex', 'Q-Max'],
          textStyle: {
            color: '#AFC0D5',
            fontSize: 12,
          },
          top: '5%'
        },
        series: [
          {
            name: '中小型',
            type: 'bar',
            barWidth: '20%',
            color: '#0DBEFF',
            data: [260,680,360,460,150,320],
          },
          {
            name: 'Q-Flex',
            type: 'bar',
            barWidth: '20%',
            color: '#31E683',
            data: [260,180,360,260,150,320],
          },
          {
            name: 'Q-Max',
            type: 'bar',
            barWidth: '20%',
            color: '#79F6FF',
            data: [260,680,260,260,150,220],
          },
        ],
      },
    })
    const initeCharts = () => {
      let myChart = echarts.init(document.getElementById('myChart1'))
      // 绘制图表
      myChart.setOption(state.option)
    }

    onMounted(() => {
      initeCharts()
    })

    return {
      ...toRefs(state),
    }
  },
})
</script>

<style scoped>

</style>
